<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>百商汇</title>
	<meta name="viewport" content="initial-scale = 1.0,maximum-scale = 1.0,minimum-scale = 1.0,user-scalable = no,width = device-width">
	<meta name="format-detection" content="telephone=no" />
	<link rel="stylesheet" type="text/css" href="../csses/transfer.css">
	<script type="text/javascript">
		if(location.pathname != '/h5/views/login.html' && !sessionStorage.token){
			window.location.href = 'login.html';
		}
	</script>
</head>
<body>
	<div class="transfer_title">
		转账
		<img src="../image/back.png" onclick="goBack()">
	</div>
	<div class="transfer_box">
		<ul class="ul">
			<li class="telNum">
				<span>手 机 号</span>
				<input type="text" placeholder="请输入收款人手机号" class="toMobile input"></input>
			</li>
			<li class="amount">
				<span>金&nbsp;&nbsp;额</span>
				<input type="text" placeholder="请输入金额" class="money input"></input>
			</li>
			<li class="payWays">
				<span>支付方式</span>
				<input type="text" placeholder="请选择支付方式" class="payWays" readonly="true"></input>
				<div class="choose">
					<img src="../image/bottom.png">
				</div>
			</li>
			<li class="payPsw">
				<span>支付密码</span>
				<input type="password" placeholder="请输入百商汇支付密码" class="paypassword input"></input>
				<div class="choose">
					<img src="../image/psw.png">
				</div>
			</li>
			<li class="remarks">
				<span>备&nbsp;&nbsp;注</span>
				<input type="text" placeholder="请输入备注" class="memo input"></input>
			</li>
		</ul>
		<button class="submitBtn">确认</button>

		<div id="hidden_box">
			<ul>
				<li>请选择充值方式</li>
				<li class="content">余额</li>
			</ul>
		</div>

		<div class="remindBox"></div>
	</div>

	<script type="text/javascript" src="../lib/flexible.js"></script>
	<script type="text/javascript" src="../lib/jquery-1.10.1.min.js"></script>
	<script type="text/javascript">
		function goBack(){
			window.history.back();
		}

		$('.input').focus(function(){
			this.select();
		});

		$('.payWays').click(function(){
			$('#hidden_box').css('display','block');
		});

		$('.content').click(function(){
			$('.payWays').attr('value',$(this).text());
			$('#hidden_box').css('display','none');
		});

		var $remindBox = $('.remindBox');

		function remind(a){
			$remindBox.css('display','block');
			$remindBox.text(a);
			setTimeout(function(){
				$remindBox.css('display','none');
			},1500);
		}

		$('.submitBtn').click(function(){
			var $toMobile = $('.toMobile').val();
			var $money = $('.money').val();
			var $paypassword = $('.paypassword').val();
			var $memo = $('.memo').val();
			

			if(!$toMobile){
				remind('请输入收款人手机号');
			}else if(!(/^1[3|4|5|7|8]\d{9}$/.test($toMobile))){
				remind('请输入正确的手机号');
			}else if(!$money){
				remind('请输入转账金额');
			}else if(!$paypassword){
				remind('请输入支付密码');
			}

			if($('.payWays').attr('value') == '余额'){
				$.ajax({
					type : 'post',
					url : '/api/v1/finance/transfer/balance',
					data : {
						paramStr : "{'userName':'" + sessionStorage.userName + "','token':'" + sessionStorage.token + "','paypassword':'" + $paypassword + "','money':'" + $money + "','memo':'" + $memo +"','toMobile':'" + $toMobile + "'}"
					},
					dataType : 'json',
					timeout : 10000,
					success : function (data) {
						remind(data.message);
						if(data.code == 200){
							$('.submitBtn').attr('disabled',true).css('background','#ccc');
							setTimeout(function(){
								window.location.href = '../index1.html';
							},1500);
						}
					},
					error : function (xhr,type,errorThrown) {
						// alert('未知错误');
					}
				});
			}
		});
	</script>
</body>
</html>